﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;
namespace Human
{
	/// <summary>
	/// Summary description for frmInLyLichTrichNgang.
	/// </summary>
	public class frmbc_dienbienhesoluongnv : System.Windows.Forms.Form
	{
        AccessData mDB = new AccessData();
        Language lan = new Language();
		private DataSet ds =new DataSet();
        string sql = "", m_user = "",s_mmyy="",s_bophan="",user_dn="";
        DataSet ds_hoten = new DataSet();

        private bool bClear = true;
        private System.Windows.Forms.Button butXem;
		private System.Windows.Forms.Button butIn;
        private System.Windows.Forms.Button butThoat;
        private Button btnexel;
        private LibList.List lst_lgnv;
        private Label label3;
        private TextBox txt_manv;
        private Label label4;
        private TextBox txt_hoten;
        private Label label1;
		private System.ComponentModel.Container components = null;

		public frmbc_dienbienhesoluongnv(string s_makp,string s_userdn)
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            s_bophan = s_makp;
            user_dn = s_userdn;
        }
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmbc_dienbienhesoluongnv));
            this.butThoat = new System.Windows.Forms.Button();
            this.butIn = new System.Windows.Forms.Button();
            this.butXem = new System.Windows.Forms.Button();
            this.btnexel = new System.Windows.Forms.Button();
            this.lst_lgnv = new LibList.List();
            this.label3 = new System.Windows.Forms.Label();
            this.txt_manv = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.txt_hoten = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // butThoat
            // 
            this.butThoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butThoat.Image = global::Human.Properties.Resources.close_r;
            this.butThoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butThoat.Location = new System.Drawing.Point(212, 95);
            this.butThoat.Name = "butThoat";
            this.butThoat.Size = new System.Drawing.Size(60, 28);
            this.butThoat.TabIndex = 5;
            this.butThoat.Text = "Thoát";
            this.butThoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butThoat.Click += new System.EventHandler(this.butThoat_Click);
            // 
            // butIn
            // 
            this.butIn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butIn.Image = global::Human.Properties.Resources.t_printer;
            this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butIn.Location = new System.Drawing.Point(81, 95);
            this.butIn.Name = "butIn";
            this.butIn.Size = new System.Drawing.Size(60, 28);
            this.butIn.TabIndex = 4;
            this.butIn.Text = "In";
            this.butIn.Click += new System.EventHandler(this.butIn_Click);
            // 
            // butXem
            // 
            this.butXem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butXem.Image = global::Human.Properties.Resources.t_search;
            this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butXem.Location = new System.Drawing.Point(16, 95);
            this.butXem.Name = "butXem";
            this.butXem.Size = new System.Drawing.Size(60, 28);
            this.butXem.TabIndex = 2;
            this.butXem.Text = "  Xem";
            this.butXem.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butXem.Click += new System.EventHandler(this.butXem_Click);
            // 
            // btnexel
            // 
            this.btnexel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnexel.Image = global::Human.Properties.Resources.white_excel;
            this.btnexel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btnexel.Location = new System.Drawing.Point(147, 95);
            this.btnexel.Name = "btnexel";
            this.btnexel.Size = new System.Drawing.Size(60, 28);
            this.btnexel.TabIndex = 3;
            this.btnexel.Text = "Excel";
            this.btnexel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btnexel.Click += new System.EventHandler(this.btnexel_Click);
            // 
            // lst_lgnv
            // 
            this.lst_lgnv.ColumnCount = 0;
            this.lst_lgnv.FormattingEnabled = true;
            this.lst_lgnv.Location = new System.Drawing.Point(16, 129);
            this.lst_lgnv.MatchBufferTimeOut = 1000;
            this.lst_lgnv.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.lst_lgnv.Name = "lst_lgnv";
            this.lst_lgnv.Size = new System.Drawing.Size(55, 17);
            this.lst_lgnv.TabIndex = 20;
            this.lst_lgnv.TextIndex = -1;
            this.lst_lgnv.TextMember = null;
            this.lst_lgnv.ValueIndex = -1;
            this.lst_lgnv.Visible = false;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(8, 44);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(43, 13);
            this.label3.TabIndex = 19;
            this.label3.Text = "Mã NV:";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txt_manv
            // 
            this.txt_manv.Enabled = false;
            this.txt_manv.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txt_manv.Location = new System.Drawing.Point(11, 64);
            this.txt_manv.MaxLength = 50;
            this.txt_manv.Name = "txt_manv";
            this.txt_manv.Size = new System.Drawing.Size(58, 22);
            this.txt_manv.TabIndex = 0;
            this.txt_manv.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_manv_KeyDown);
            this.txt_manv.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_manv_KeyPress);
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(75, 44);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(45, 13);
            this.label4.TabIndex = 16;
            this.label4.Text = "Họ tên :";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txt_hoten
            // 
            this.txt_hoten.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txt_hoten.Location = new System.Drawing.Point(75, 64);
            this.txt_hoten.MaxLength = 50;
            this.txt_hoten.Name = "txt_hoten";
            this.txt_hoten.Size = new System.Drawing.Size(197, 22);
            this.txt_hoten.TabIndex = 1;
            this.txt_hoten.TextChanged += new System.EventHandler(this.txt_hoten_TextChanged);
            this.txt_hoten.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_hoten_KeyDown);
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(25, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(247, 18);
            this.label1.TabIndex = 21;
            this.label1.Text = "DIỄN BIẾN LƯƠNG NHÂN VIÊN";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // frmbc_dienbienhesoluongnv
            // 
            this.ClientSize = new System.Drawing.Size(300, 155);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.lst_lgnv);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.txt_manv);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txt_hoten);
            this.Controls.Add(this.btnexel);
            this.Controls.Add(this.butThoat);
            this.Controls.Add(this.butIn);
            this.Controls.Add(this.butXem);
            this.ForeColor = System.Drawing.Color.DarkBlue;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmbc_dienbienhesoluongnv";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Diễn biến lương nhân viên";
            this.Load += new System.EventHandler(this.frmbc_dienbienhesoluongnv_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

        private DataSet load_hoten()
        {
            string sql = "SELECT manv,ho||' '||ten AS hoten from " + mDB.user + ".llnv order by manv";
            return mDB.get_data(sql);
        }
        private void frmbc_dienbienhesoluongnv_Load(object sender, EventArgs e)
        {          
            txt_hoten.Focus();
            ds_hoten = load_hoten();
            lst_lgnv.DataSource = ds_hoten.Tables[0];
            lst_lgnv.DisplayMember = "manv";
            lst_lgnv.ValueMember = "hoten";
        }

		private void butThoat_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}        
		
		private void butXem_Click(object sender, System.EventArgs e)
		{          
				print(1);
		}
		private void butIn_Click(object sender, System.EventArgs e)
		{           
                print(1);
		}

		private void ckbToanCongTy_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode.ToString() == "Enter")
				SendKeys.Send("{Tab}");		
		}		

		private void txbHoTenNV_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode.ToString() == "Enter")
			{
				SendKeys.Send("{Tab}");
				this.Size=new Size(328,352);
			}
		}

		private void dgrXemLyLich_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode.ToString() == "Enter")
				SendKeys.Send("{Tab}{F4}");
		}	
        
        private void print(int prn)
        {
            m_user = mDB.user;
            s_mmyy = DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Year.ToString().Substring(2, 2);
            try
            {
                DataSet dstmp = new DataSet();
                 ExportToExcel exp = new ExportToExcel();
                string sql = " select l.manv,trim(l.ho)||' '||trim(l.ten) as hoten,l.phai,to_char(l.ngaysinh,'dd/mm/yyyy') as ngaysinh";
                sql += " ,mh.tenhd  as lable,to_char(hd.tungay,'dd/mm/yyyy') as tungay,hd.tungay as tn,to_char(hd.denngay,'dd/mm/yyyy') as denngay,cv.diengiai as chucvu,bp.tenbp as bophan,hd.mangach as mangach,hd.bac as bac,hd.hs_lc as hs_lc";
                sql += " from " + m_user + ".llnv l left join " + m_user + ".hopdong hd on l.manv=hd.manv";
                sql += " left join " + m_user + ".mahd mh on hd.loaihd=mh.mahd";
                sql += " left join " + m_user + ".dmcv cv on hd.macv=cv.macv";
                sql += " left join " + m_user + ".bophan bp on l.madv=bp.madv";
                sql += " where hd.ngaynghi is null";
                if (txt_manv.Text!="")
                {
                    sql += " and l.manv='" + txt_manv.Text.Trim() + "'";
                }

                sql += " UNION";
                sql += " select l.manv,trim(l.ho)||' '||trim(l.ten) as hoten,l.phai,to_char(l.ngaysinh,'dd/mm/yyyy') as ngaysinh";
                sql += " ,case when bl.mangachcu <> bl.mangachmoi then 'Nâng ngạch' else 'Nâng lương' end  as lable,to_char(bl.ngaygiubac,'dd/mm/yyyy') as tungay,bl.ngaygiubac as tn,to_char(bl.ngaynangbac,'dd/mm/yyyy') as denngay,cv.diengiai as chucvu,bp.tenbp as bophan,bl.mangachcu as mangach,to_number(trim(substring(bl.bacluongcu,1,2)),'99') as bac,to_number(trim(substring(bl.bacluongcu,6,7)),'9D9999') as hs_lc  ";
                sql += " from " + m_user + ".llnv l left join " + m_user + ".hopdong hd on l.manv=hd.manv";
                sql += " left join " + m_user + ".thaydoi_bluong bl on l.manv=bl.manv";
                sql += " left join " + m_user + ".mahd mh on hd.loaihd=mh.mahd";
                sql += " left join " + m_user + ".dmcv cv on bl.macv=cv.macv";
                sql += " left join " + m_user + ".bophan bp on bl.madv=bp.madv";
                sql += " inner join " + m_user + ".max_lan ml on hd.manv=ml.manv";
                sql += " where hd.ngaynghi is null and hd.lan=ml.lan";
                if (txt_manv.Text != "")
                {
                    sql += " and l.manv='" + txt_manv.Text.Trim() + "'";
                }
                sql += " UNION";
                sql += " select l.manv,trim(l.ho)||' '||trim(l.ten) as hoten,l.phai,to_char(l.ngaysinh,'dd/mm/yyyy') as ngaysinh ";
                sql += " ,case when pc.loaiphucap ='vk' then 'Thay đổi hệ số vượt khung(%)' when pc.loaiphucap ='cv' ";
                sql += " then 'Thay đổi phụ cấp chức vụ' ";
                sql += " when pc.loaiphucap='th' then 'Thay đổi phụ cấp thu hút'";
                sql += " when pc.loaiphucap='dh' then 'Thay đổi phụ cấp độc hại'";
                sql += " when pc.loaiphucap='dt' then 'Thay đổi phụ cấp đặc thù'";
                sql += " when pc.loaiphucap='ud' then 'Thay đổi phụ cấp ưu đãi'";
                sql += " else null end  as lable";
                sql += " ,to_char(pc.ngayquydinh,'dd/mm/yyyy') as tungay,pc.ngayquydinh as tn,to_char(pc.ngaygiu,'dd/mm/yyyy') as denngay ,cv.diengiai as chucvu,bp.tenbp as bophan";
                sql += " ,hd.mangach as mangach,hd.bac as bac ,";
                sql += " case when pc.loaiphucap ='vk' then pc.hs_cu*100 when pc.loaiphucap='cv' then pc.hs_cu ";              
                sql += "  when pc.loaiphucap='th' then pc.hs_cu";
                sql += " when pc.loaiphucap='dh' then pc.hs_cu";
                sql += " when pc.loaiphucap='dt' then pc.hs_cu "; 
                sql += " when pc.loaiphucap='ud' then pc.hs_cu*100";
                sql += " else 0 end as hs_lc";
                sql += " from " + m_user + ".llnv l left join " + m_user + ".hopdong hd on l.manv=hd.manv left join " + m_user + ".thaydoi_phucap pc on l.manv=pc.manv ";
                sql += " left join " + m_user + ".mahd mh on hd.loaihd=mh.mahd left join " + m_user + ".dmcv cv on pc.macv=cv.macv ";
                sql += " left join " + m_user + ".bophan bp on pc.madv=bp.madv inner join " + m_user + ".max_lan ml on hd.manv=ml.manv";
                sql += " where hd.ngaynghi is null and hd.lan=ml.lan and pc.loaiphucap<>''";
                if (txt_manv.Text != "")
                {
                    sql += " and l.manv='" + txt_manv.Text.Trim() + "'";
                }
                sql += " order by tn";                
                ds = mDB.get_data(sql);
                ds.WriteXml("..\\xml\\h_dienbienluongnv.xml", XmlWriteMode.WriteSchema);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    switch (prn)
                    {
                        case 1: frmReport f = new frmReport(mDB, ds,lan.Change_language_MessageText( " DIỄN BIẾN LƯƠNG NHÂN VIÊN "), "h_dienbienluongnv.rpt",user_dn);
                            f.ShowDialog(this);
                            break;
                        case 2: dstmp = ds;
                            exp.exp_exel_dienbienluong(dstmp, "DIENBIENLUONGNHANVIEN", DateTime.Now.Year.ToString(),user_dn);
                            break;
                    }                  
                }
                else
                {
                    MessageBox.Show(lan.Change_language_MessageText("Chưa có đầy đủ dữ liệu"),lan.Change_language_MessageText( "Thông Báo"));                  
                }
            }
            catch { }
        }
        private DataSet xuat_exel(DataSet dse)
        {
            string[] str = new string[] {lan.Change_language_MessageText( "STT"),lan.Change_language_MessageText( "Họ Tên"),lan.Change_language_MessageText( "Nam"),lan.Change_language_MessageText( "Nữ"),lan.Change_language_MessageText( "Quê Quán"),lan.Change_language_MessageText( "Nơi Ở"),lan.Change_language_MessageText( "Dân Tộc"),lan.Change_language_MessageText( "Văn Hoá"),lan.Change_language_MessageText( "Ngày TGCM"),lan.Change_language_MessageText( "Ngày Vào Đoàn"), lan.Change_language_MessageText("Ngày vào Đảng"),lan.Change_language_MessageText( "Chức Vụ"),lan.Change_language_MessageText("Chuyên Môn"),lan.Change_language_MessageText( "Tên Cha"),lan.Change_language_MessageText( "Năm Sinh"),lan.Change_language_MessageText( "Nơi Ở"),lan.Change_language_MessageText( "Nghề Nghiệp"),lan.Change_language_MessageText( "Tên Mẹ"),lan.Change_language_MessageText( "Năm Sinh"),lan.Change_language_MessageText( "Nơi Ở"),lan.Change_language_MessageText( "Nghề Nghiệp"),lan.Change_language_MessageText( "Tên Vợ"),lan.Change_language_MessageText( "Năm Sinh"),lan.Change_language_MessageText( "Nơi Ở"),lan.Change_language_MessageText( "Nghề Nghiệp") };
            DataSet dse1 = new DataSet();
            dse1.Tables.Add();
            dse1.Tables[0].Columns.Add("stt",typeof(string));
            dse1.Tables[0].Columns.Add("hoten",typeof(string));
            dse1.Tables[0].Columns.Add("nsNam",typeof(string));
            dse1.Tables[0].Columns.Add("nsNu",typeof(string));
            dse1.Tables[0].Columns.Add("quequan",typeof(string));
            dse1.Tables[0].Columns.Add("truquan",typeof(string));
            dse1.Tables[0].Columns.Add("dantoc",typeof(string));
            dse1.Tables[0].Columns.Add("hocvan",typeof(string));
            dse1.Tables[0].Columns.Add("ngay_t_gia",typeof(string));
            dse1.Tables[0].Columns.Add("ngay_doan",typeof(string));
            dse1.Tables[0].Columns.Add("cthuc_dang",typeof(string));
            dse1.Tables[0].Columns.Add("chucvu",typeof(string));
            dse1.Tables[0].Columns.Add("bangcap",typeof(string));
            dse1.Tables[0].Columns.Add("tenCha",typeof(string));
            dse1.Tables[0].Columns.Add("nsCha", typeof(string));
            dse1.Tables[0].Columns.Add("noioCha", typeof(string));
            dse1.Tables[0].Columns.Add("tenMe", typeof(string));
            dse1.Tables[0].Columns.Add("nsMe", typeof(string));
            dse1.Tables[0].Columns.Add("noioMe", typeof(string));
            //dse1.Tables[0].Columns.Add("nnMe", typeof(string));
            dse1.Tables[0].Columns.Add("tenVc", typeof(string));
            dse1.Tables[0].Columns.Add("nsVc", typeof(string));
            dse1.Tables[0].Columns.Add("noioVc", typeof(string));
            //dse1.Tables[0].Columns.Add("nnVc", typeof(string));

            DataRow nrow;
            int stt=0;
            foreach (DataRow r in dse.Tables[0].Rows)
            {
                stt++;
                nrow = dse1.Tables[0].NewRow();
                nrow["stt"] = stt.ToString();
                nrow["hoten"] = r["hoten"].ToString();
                nrow["nsNam"] = r["nsNam"].ToString();
                nrow["nsNu"] = r["nsNu"].ToString();
                nrow["quequan"] = r["quequan"].ToString();
                nrow["truquan"] = r["truquan"].ToString();
                nrow["dantoc"] = r["dantoc"].ToString();
                nrow["hocvan"] = r["hocvan"].ToString();
                nrow["ngay_t_gia"] = r["ngay_t_gia"].ToString();
                nrow["ngay_doan"] = r["ngay_doan"].ToString();
                nrow["cthuc_dang"] = r["cthuc_dang"].ToString();
                nrow["bangcap"] = r["bangcap"].ToString();
                nrow["tenCha"] = r["tenCha"].ToString();
                nrow["nsCha"] = r["nsCha"].ToString();
                //nrow["nnCha"] = r["nnCha"].ToString();
                nrow["tenMe"] = r["tenMe"].ToString();
                nrow["nsMe"] = r["nsMe"].ToString();
                nrow["noioMe"] = r["noioMe"].ToString();
                //nrow["nnMe"] = r["nnMe"].ToString();
                nrow["tenVc"] = r["tenVc"].ToString();
                nrow["nsVc"] = r["nsVc"].ToString();
                nrow["noioVc"] = r["noioVc"].ToString();
                //nrow["nnVc"] = r["nnVc"].ToString();
                dse1.Tables[0].Rows.Add(nrow);
            }
            return dse1;
        }

        private void btnexel_Click(object sender, EventArgs e)
        {
           
                print(2);
        }
        DataSet Ten_NV(string madv)
        {
            return mDB.get_data("SELECT manv,ho||' '||ten AS hoten" +
                " FROM " + mDB.user + ".llnv WHERE madv ='" + madv + "' order by manv");
        }
        private DataSet TenNV()
        {
            return mDB.get_data("SELECT manv,ho||' '||ten AS hoten from " + mDB.user + ".llnv order by manv");
        }       

        private void cbobBoPhan_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}{F4}");
        }

        private void cbo_hoten_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                butXem.Focus();
        }

        private void txt_manv_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up))
            {
                this.lst_lgnv.Focus();
            }
            else if (e.KeyCode == Keys.Return)
            {
                if (this.lst_lgnv.Visible)
                {
                    this.lst_lgnv.Focus();
                }
                else
                {
                    SendKeys.Send("{Tab}");
                }
            }
        }

        private void txt_manv_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!IsNumeric(e.KeyChar.ToString()))
                e.Handled = true;
            if (e.KeyChar == 8 || e.KeyChar == '.')
                e.Handled = false;
        }
        private bool IsNumeric(string strNum)
        {
            int iNum;
            try
            {
                iNum = int.Parse(strNum);
                return true;
            }
            catch
            {
                return false;
            }
        }

        private void txt_hoten_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up))
            {
                this.lst_lgnv.Focus();
            }
            else if (e.KeyCode == Keys.Return)
            {
                if (this.lst_lgnv.Visible)
                {
                    this.lst_lgnv.Focus();
                }
                else
                {
                    SendKeys.Send("{Tab}");
                }
            }
        }

        private void txt_hoten_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.ActiveControl == this.txt_hoten)
                {
                    this.loc_hoten(txt_hoten.Text.Trim());
                    this.lst_lgnv.BrowseToTennv(txt_hoten, txt_manv, txt_hoten, 500);
                }
            }
            catch { };
        }
        private void loc_hoten(string hoten)
        {
            try
            {
                CurrencyManager cm = (CurrencyManager)this.BindingContext[lst_lgnv.DataSource];
                DataView dv = (DataView)cm.List;
                dv.RowFilter = "hoten like '%" + hoten.Trim() + "%' ";
            }
            catch
            {

            }
        }
      
	}

}